package com.ruoyi.system.api.user.login.produce.impl;

import com.ruoyi.auth.api.IUserLoginInfoApiService;
import com.ruoyi.auth.api.model.dto.UserLoginInfoDto;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysPermissionService;
import com.ruoyi.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;


@Service("SystemUserLoginService")
@Slf4j
public class UserLoginInfoApiService implements IUserLoginInfoApiService {

    @Autowired
    private ISysUserService userService;

    @Autowired
    private ISysPermissionService permissionService;


    public UserLoginInfoDto SysUserToUserInfo(SysUser sysUser) {
        UserLoginInfoDto userInfo = null;
        if (sysUser != null) {
            // 角色集合
            Set<String> roles = permissionService.getRolePermission(sysUser.getUserId());
            // 权限集合
            Set<String> permissions = permissionService.getMenuPermission(sysUser.getUserId());
            userInfo = new UserLoginInfoDto();
            BeanUtils.copyProperties(sysUser, userInfo);
            userInfo.setRoles(roles);
            userInfo.setPermissions(permissions);
        }

        return userInfo;
    }

    @Override
    public UserLoginInfoDto getUserInfo(String username) {
        log.info("{}开始登陆:{}", username);
        SysUser sysUser = userService.selectUserByUserName(username);
        return SysUserToUserInfo(sysUser);
    }

    @Override
    public UserLoginInfoDto getUserInfoByPhone(String phoneNumber, String inviteCode) {
        return null;
    }

    @Override
    public UserLoginInfoDto getUserInfoByEmail(String email, String inviteCode) {
        return null;
    }

    @Override
    public UserLoginInfoDto getUserInfoByThird(String username, String appType, String thirdCode, String inviteCode) {
        return null;
    }

    @Override
    public UserLoginInfoDto thirdBinding(String username, String appType, String phone, String thirdCode, String inviteCode) {
        return null;
    }


}
